﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using My.Common.Helper.Utils;
using WarehouseManagement.BusinessLogic.BC;
using WarehouseManagement.Shared;
using WarehouseManagement.Views.Shared;

namespace WarehouseManagement.Views.Login
{
    public partial class LoginForm : DevExpress.XtraEditors.XtraForm
    {
        UserBC _userBC;

        public LoginForm()
        {
            InitializeComponent();
            _userBC = new UserBC();
        }

        private void btnServerConfig_Click(object sender, EventArgs e)
        {
            ServerConfig FrmServerConfig = new ServerConfig();
            FrmServerConfig.ShowDialog();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
           
            var auth = _userBC.Authenticate(txtUserName.Text, txtPassword.Text);
            if (!auth)
            {


                XtraMessageBox.Show("Tên đăng nhập hoặc mật khẩu không chính xác. Xin vui lòng thử lại sau.", "Đăng nhập thất bại", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;

            }
            GlobalMemory.CurrentLoginUser = txtUserName.Text;

            this.Hide();
            MainForm mainForm = new MainForm();
            mainForm.OnFormClosed = new MainForm.FormClosedDelegate(mainFormClosed);
            mainForm.Show();
        }

        private void mainFormClosed()
        {
            this.Show();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}